TOP

VBA Function: InStrRev

Description

The VBA INSTRREV Function returns an integer corresponding to the first position found of a value in a character string starting the search from the right.

The InStrRev function returns 0 if no match was found.


INSTRREV Syntax

InStrRev(text, value)

Or

InStrRev(text, value, start_num, case)

VBA InStrRev Example

Determine the position of the value XLP starting the search from the right of the text:

Sub InStrRevExample()
    
    text = "REF: XLP-54-21-XLP-9"
    
    'First position of "XLP" in the text when searching from the right
    position = InStrRev(text, "XLP")
    
    MsgBox position 'Returns: 17
    
End Sub
The function that finds the position of a value from the left of the text is the INSTR function.

The YLC Utilities menu in LO Calc

The YLC Utilities menu in LO Calc

The YLC Utilities menu in Excel

The YLC Utilities menu in Excel